//------------------------------------------------------------------------

/*
 * Clock, GUI DOM element to show clock on right top corner
 * to do: other corners if needed or design changes
 */	

if (!(Clock instanceof Object)) {

	var Clock = function (config) {

		this.id			= mjdevjs.createUUID();
		this.renderTo	= mjdevjs._body;
		this.visible 	= false;

		mjdevjs.config(this, config);

	};

	/*
	 * create and show gui element
	 * params:
	 * id - element id will be created
	 * where_to, if is set element will be appended to this DOM element
	 */
	Clock.prototype.create = function () {

		this.canvas	= mjdevjs.me({type:mjdevjs.DOM_TYPE_DIV, id:this.id,  append:this.append});
		this.canvas.hide();
		this.txt	= mjdevjs.me({type:mjdevjs.DOM_TYPE_DIV, id:'txt', append:this.canvas});
		this.txt1	= mjdevjs.me({type:mjdevjs.DOM_TYPE_DIV, id:'txt1', append:this.canvas});
		this.theme	= mjdevjs.me({type:mjdevjs.DOM_TYPE_DIV, id:'theme', append:this.canvas});

	};

	/*
	 * function to update time/date
	 * internal, should be not touched anyway
	 * to do:
	 * stop function
	 * start function
	 * remove function
	 */
	Clock.prototype.update = function () {

		if (!this.visible) return;

		var dt = new Date();
		this.txt.innerHTML = '<div id="text" style="float:left">'+dt.to00(dt.getHours(),2) + '</div><div id="text" style="float:right">' + dt.to00(dt.getMinutes(),2)+'</div>';
		this.txt1.innerHTML = '<div id="text1">'+dt.toLocaleDateString()+'</div>';

	};

	Clock.prototype.show = function () { 

		if (!this.visible) {

			this.canvas.show(); 
			this.visible = true;
			this.update();
			this.interval = window.setInterval(mjdevjs.close(this, this.update), 1000);

		}

	};

	Clock.prototype.hide = function () { 

		if (this.visible) {

			window.clearInterval(this.interval);
			this.canvas.hide();
			this.visible = false;

		}

	};

};

//------------------------------------------------------------------------
